# Copyright (c) 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# GNU Makefile based on shared rules provided by the Native Client SDK.
# See README.Makefiles for more details.

CFLAGS:=-g -O2 -pthread -D__ANDROID__ -DANDROID -DBIONIC -fPIC
CFLAGS+=-fno-stack-protector -fexceptions
#CFLAGS+=-fno-stack-protector -fexceptions -fvisibility=hidden

CFLAGS_WARNINGS:=-Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wold-style-definition

CFLAGS_INCLUDES:=-I.
CFLAGS_INCLUDES+=-I$(INS_ROOT)/../include
CFLAGS_INCLUDES+=-I$(NATIVE_CLIENT_PATH)/toolchain_build/src/pnacl-gcc/gcc/libgcc
CFLAGS_INCLUDES+=-I$(NATIVE_CLIENT_PATH)/toolchain_build/src/pnacl-gcc/gcc 
CFLAGS_INCLUDES+=-I$(NATIVE_CLIENT_PATH)/toolchain_build/src/pnacl-gcc/include

CFLAGS_DEFINES:=-DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -DIN_LIBGCC2 
CFLAGS_DEFINES+=-D__GCC_FLOAT_NOT_NEEDED -Dinhibit_libc -DHAVE_CC_TLS 
CFLAGS_DEFINES+=-DHIDE_EXPORTS -DENABLE_RUNTIME_CHECKING
CFLAGS_DEFINES+=-DLIBGCC2_UNWIND_ATTRIBUTE=

CFLAGS+=$(CFLAGS_WARNINGS) $(CFLAGS_INCLUDES) $(CFLAGS_DEFINES)
DYNAMIC_LINK_FLAGS:=-nostdlib -shared  -L$(INS_ROOT) -L$(GCC_ROOT)
# -Wl,-z,defs

ifeq ($(GCC_ARCH),arm)
endif

ifeq ($(GCC_ARCH),x86_64)
endif

ifeq ($(GCC_ARCH),i686)
endif


LIBGCC_S_SOURCES:=unwind-dw2.c unwind-dw2-fde-glibc.c
LIBGCC_S_OBJECTS:=$(subst .S,.o,$(subst .c,.o,$(LIBGCC_S_SOURCES)))

$(foreach src,$(LIBGCC_S_SOURCES),$(eval $(call BASIC_COMPILE_TARGET,$(basename $(src)).o,$(SRC_ROOT)/$(src),$(GCC),$(CFLAGS) $(ARCH_FLAGS))))

$(eval $(call BASIC_LIB_TARGET,$(INS_ROOT)/libgcc_eh.a,$(LIBGCC_S_OBJECTS),$(AR)))
$(eval $(call BASIC_LINK_TARGET,$(INS_ROOT)/libgcc_s.so,$(INS_ROOT)/crtbeginS.o $(LIBGCC_S_OBJECTS) $(INS_ROOT)/crtendS.o ,$(CC),$(DYNAMIC_LINK_FLAGS), -lgcc,,$(INS_ROOT)/libdl.so))

all: compile lib

clean:
	rm *.o